package com.frxuexi.mdm2206.demo

import android.util.Log
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil3.compose.AsyncImage
//import coil.compose.AsyncImage
//import androidx.constraintlayout.compose.ConstraintLayout
import com.frxuexi.mdm2206.R

@Composable
fun MyCom(name: String, age: Int = 18) {
    //Column:垂直布局,Row:水平布局
    /*Row(Modifier.fillMaxSize(),horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically) {
//        Text(text = "hello $name,$age", color = Color.Red)
        Text(text = "aa")
        Text(text = "aa")
        Text(text = "aa")
        Text(text = "aa")
    }*/
    Column(
        Modifier.fillMaxSize(),
        verticalArrangement = Arrangement.SpaceEvenly,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
//        Text(text = "hello $name,$age", color = Color.Red)
        Text(
            text = "aadafsghdjkcvlbkjhshdhsjd",
            modifier = Modifier
                .width(100.dp)
                .background(Color.Green),
            color = colorResource(id = R.color.purple_200),
            fontSize = 28.sp,
            fontWeight = FontWeight.Bold,
            letterSpacing = 5.sp,
            textAlign = TextAlign.Center,
            maxLines = 1,
            overflow = TextOverflow.Ellipsis
        )
        Text(text = "aa")
        Text(text = "aa")
        Text(text = "aa")
    }


}

//@Preview
@Composable
fun MyCom2() {
    //状态可变的变量，用于驱动更新UI
    var name by remember {
        mutableStateOf("")
    }
    Column(
        Modifier
            .fillMaxSize()
            .padding(20.dp, 10.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(20.dp)) {
        Spacer(modifier = Modifier.height(50.dp))
//        OutlinedTextField
        TextField(modifier = Modifier.fillMaxWidth(),
            value = name,
            onValueChange = {
                name = it
            },
            label = { Text(text = "用户名") },
            leadingIcon = {//左侧位置图标
                Icon(
                    imageVector = Icons.Default.AccountCircle,
                    contentDescription = ""
                )
            },
            trailingIcon = {//右侧位置图标/文字
//            Text(text = "验证码")
                Icon(
                    painter = painterResource(id = R.drawable.ic_action_eye),
                    contentDescription = ""
                )
            },
            visualTransformation = PasswordVisualTransformation(),//密文
            shape = RoundedCornerShape(20.dp),
            colors = TextFieldDefaults.colors(unfocusedContainerColor = Color.LightGray, focusedContainerColor = Color.Yellow,
                unfocusedTextColor = Color.Green, focusedTextColor = Color.Red,
                unfocusedIndicatorColor=Color.White,focusedIndicatorColor=Color.White
            )
        )

        Text(text = "aa")
        Text(text = "bb")

        Image(painter = painterResource(id = R.drawable.ic_launcher_background), contentDescription = "",
            alpha = 1f, modifier = Modifier.clip(CircleShape))

        AsyncImage(model = "https://img0.baidu.com/it/u=540669065,2162680038&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1731517200&t=ca5fe9ebbbd421d132d7b00198089aa8", contentDescription = "",
        modifier = Modifier
            .size(100.dp)
            .clip(CircleShape),contentScale= ContentScale.Crop)

        Button(modifier = Modifier.width(200.dp).height(50.dp), onClick = {
                         Log.i("===","登录了")
        },colors= ButtonDefaults.buttonColors(containerColor = Color.Red, contentColor = Color.Yellow), border = BorderStroke(1.dp,Color.Blue)) {
            Text(text = "登录")
        }

        OutlinedButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }

        ElevatedButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }

        TextButton(onClick = { /*TODO*/ }) {
            Text(text = "登录")
        }
    }
}
